trimwhitespace {C}
νμ΄μ¬ strip
κ°μ ν¨μκ° νμνλ€. κ·Έλμ κ²μν΄λ³΄λ strip_left
λ λ¨μν λ¦¬ν΄ ν¬μΈν°λ₯Ό λ°κΏμ ν΄κ²°νκ³ , strip_right
λ λ€μμλΆν° μννλ©° νμ΄νΈμ€νμ΄μ€κ° μλ μμΉ +1μ \0
μ λ¬μμ λ¬Έμ λ₯Ό ν΄κ²°νλ€.
// Note: This function returns a pointer to a substring of the original string.
// If the given string was allocated dynamically, the caller must not overwrite
// that pointer with the returned value, since the original pointer must be
// deallocated using the same allocator with which it was allocated. The return
// value must NOT be deallocated using free() etc.
char *trimwhitespace(char *str)
{
char *end;
// Trim leading space
while(isspace((unsigned char)*str)) str++;
if(*str == 0) // All spaces?
return str;
// Trim trailing space
end = str + strlen(str) - 1;
while(end > str && isspace((unsigned char)*end)) end--;
// Write new null terminator character
end[1] = '\0';
return str;
}